<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2008 Starbugs <univis2typo3@googlegroups.com>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

require_once(PATH_tslib.'class.tslib_pibase.php');
require_once (t3lib_extMgm::extPath('univis2typo3') . 'pi2/class.tx_univis2typo3_pi2.php');

/**
 * Plugin 'publications' for the 'univis2typo3' extension.
 *
 * @author	Starbugs <univis2typo3@googlegroups.com>
 * @package	TYPO3
 * @subpackage	tx_univis2typo3
 */
class tx_univis2typo3_pi9 extends tslib_pibase {
	var $prefixId      = 'tx_univis2typo3_pi9';		// Same as class name
	var $scriptRelPath = 'pi9/class.tx_univis2typo3_pi9.php';	// Path to this script relative to the extension dir.
	var $extKey        = 'univis2typo3';	// The extension key.
	var $pi_checkCHash = true;
	var $department = "";
	var $template = "";
	var $cObj = "";

	/**
	 * The main method of the PlugIn
	 *
	 * @param	string		$content: The PlugIn content
	 * @param	array		$conf: The PlugIn configuration
	 * @return	The content that is displayed on the website
	 */

	function main($content, $conf)	{
		$this->conf = $conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->department = $this->conf['department_id'];

		$templateCode = $this->cObj->fileResource($this->conf['templateFile']);
		$this->template = $this->cObj->getSubpart($templateCode,"###TEMPLATE_PUBLICATIONS###");

		// Flex-Form initialisieren
		$this->pi_initPIflexForm();	
		$authorKey = $this->getPersonalKey();

		$publications = t3lib_div::makeInstance("tx_univis2typo3_pi2");
		$publications->cObj = $this->cObj;
		$publications->department = $this->conf['department_id'];
		$publications->template = $this->cObj->getSubpart($templateCode,"###TEMPLATE_PUBLICATIONS###");
		$content = $publications->getContent($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'what_to_display', 'sDEF'), $authorKey);
		return $this->pi_wrapInBaseClass($content);
	}

	function getPersonalKey(){
		// find univis key of page owner
		$select  = '`tx_univis2typo3_person_key`';
		$from    = '`be_users`';
		$where   = '`uid` = ' . (int) $GLOBALS['TSFE']->page['perms_userid'];
		$groupby = $orderby = $limit = '';
		$query = $GLOBALS['TYPO3_DB']->SELECTquery(
			$select,
			$from,
			$where,
			$groupby,
			$orderby,
			$limit
		);

		$res =& $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
		$row =& mysql_fetch_assoc($res);
		$univisPersonKey =& $row['tx_univis2typo3_person_key'];
		return $univisPersonKey;
	}
}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/univis2typo3/pi9/class.tx_univis2typo3_pi9.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/univis2typo3/pi9/class.tx_univis2typo3_pi9.php']);
}

?>
